/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bill.model.dao;

import bill.model.vo.InventoryClass;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import util.DBUtils;

/**
 *
 * @author Administrator
 */
public class InventoryClassDAO {

    public static ArrayList<InventoryClass> getAllInventoryClass(InventoryClass invCls){
        ArrayList<InventoryClass> invcs = new ArrayList<InventoryClass>();
        Connection con = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        String sql = "select cInvCCode,cInvCName,iInvCGrade,bInvCEnd from InventoryClass";
        String id = invCls.getcInvCCode();
        if(id != null){
            sql += " where cInvCCode like ?";
        }
        try{
            con = DBUtils.getDataConnection();
            pstmt = con.prepareStatement(sql);
            if(id != null){
                pstmt.setString(1, id);
            }
            rs = pstmt.executeQuery();
            while(rs.next()){
                InventoryClass invc = new InventoryClass(rs.getString(1),
                        rs.getString(2),rs.getByte(3),rs.getByte(4));
                invcs.add(invc);
            }
        } catch (SQLException ex) {
            Logger.getLogger(InventoryClassDAO.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
            DBUtils.closeAll(rs, pstmt, con);
        }
        return invcs;
    }
}
